home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14229 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: news1.erols.com!newsmaster@erols.com
  2. From: mnettles@erols.com (Mike Nettles)
  3. Newsgroups: comp.lang.c++
  4. Subject: Help:  Opening Dynamic number of input files
  5. Date: Fri, 29 Mar 1996 15:27:07 GMT
  6. Organization: Erols Internet Services
  7. Message-ID: <4jfmqa$s95@news6.erols.com>
  8. NNTP-Posting-Host: ppp67.erols.com
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. Suggestion, pointers, and / or samples sought.
  12.  
  13.  
  14. I am trying to write a sort routine that do to memory limitations
  15. swaps to disk files.  Right now the program will read in a section of
  16. the information to be sorted, sort the information and the write the
  17. section to a  temp file.  The next sections is then read in, sorted,
  18. and written to another temp file, etc.
  19.  
  20. My problem comes once all of the sort files are written, a need to
  21. combine them to make a sorted list.  this is easy enough as all I need
  22. to do is open each file, read the first argument in and the output the
  23. lowest value and read the next one in.
  24.  
  25. My problem comes in opening a dynamic number of input streams.  I
  26. can't seem to find a way to get it to work.  Can anybody give me some
  27. ideas, or perhaps a better way to do a very large sort.  An example of
  28. what I am trying to do, in pseuda code, is below.
  29.  
  30.     int combine_sort_files(int num_sort_files) {
  31.     
  32.     ifstream input[num_sort_files);
  33.     ofstream output ("sorted.dat");
  34.  
  35.     for (int tmp=0;tmp<num_sort_files;tmp++) {
  36.         input[tmp].open ("sortfile#")  
  37.     }
  38. /* note code left out in above to convert filename from int tmp into
  39. char []*/
  40.     ...
  41. /* rest of program follows */
  42.  
  43.  
  44. The above would be the way I'd prefer to do it.  The only way i have
  45. been able to get it to work is hard code a maximum number of input
  46. files by putting a constant as in 'ifstream input[const value];    '
  47.  
  48. I figure to do what I want I'll need to make a pointer and then use
  49. new to dynamically allocate the memory, but I haven't been able to
  50. figure how to get this to wrk.
  51.  
  52.  
  53. Any help is appreciated
  54.  
  55. ;-)  Even if it is to RTFM, if you post which manual and what sections
  56.  
  57.  
  58. Please replay if possible by E-mail as my news server is intermittant
  59. at best.
  60.  
  61.